package com.ctshk.sapp.system.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.rpc.system.dto.MainDataAreaNumberListDTO;
import com.ctshk.rpc.system.dto.MainDataAreaNumberQueryDTO;
import com.ctshk.rpc.system.req.MainDataAreaNumberAddReq;
import com.ctshk.rpc.system.req.MainDataAreaNumberListReq;
import com.ctshk.rpc.system.req.MainDataAreaNumberQueryReq;
import com.ctshk.rpc.system.req.MainDataAreaNumberUpdateReq;
import com.ctshk.rpc.system.service.IMainDataAreaNumberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;

/**
 * <p>
 * 区位区号表 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-02-03
 */
@Api(value = "主数据区位区号",tags = "主数据区位区号")
@RestController
@RequestMapping("/main/data/area/number")
public class MainDataAreaNumberController extends BaseController {

    @DubboReference
    private IMainDataAreaNumberService iMainDataAreaNumberService;

    @ApiOperation(value = "新增区位区号", notes = "新增区位区号")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "新增区位区号", operDesc = "新增区位区号")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid MainDataAreaNumberAddReq req){
        TokenUser currentUser = getCurrentUser(getRequest());
        req.setCreateId(currentUser.getId());
        req.setModifiedId(currentUser.getId());
        req.setModifiedName(currentUser.getUsername());
        return iMainDataAreaNumberService.add(req);
    }

    @ApiOperation(value = "编辑区位区号", notes = "编辑区位区号")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.UPDATE, operTitle = "编辑区位区号", operDesc = "编辑区位区号")
    @PostMapping("/update")
    public Result update(@RequestBody @Valid MainDataAreaNumberUpdateReq req){
        TokenUser currentUser = getCurrentUser(getRequest());
        req.setModifiedId(currentUser.getId());
        req.setModifiedName(currentUser.getUsername());
        return iMainDataAreaNumberService.update(req);
    }

    @ApiOperation(value = "查看区位区号", notes = "查看区位区号")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查看区位区号", operDesc = "查看区位区号")
    @PostMapping("/query")
    public Result<MainDataAreaNumberQueryDTO> query(@RequestBody @Valid MainDataAreaNumberQueryReq req){
        return iMainDataAreaNumberService.query(req);
    }

    @ApiOperation(value = "编辑区位区号状态", notes = "编辑区位区号状态")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.UPDATE, operTitle = "编辑区位区号", operDesc = "编辑区位区号")
    @PostMapping("/update/status")
    public Result updateStatus(@RequestBody @Valid MainDataAreaNumberQueryReq req){
        TokenUser currentUser = getCurrentUser(getRequest());
        req.setModifiedId(currentUser.getId());
        req.setModifiedName(currentUser.getUsername());
        return iMainDataAreaNumberService.updateStatus(req);
    }

    @ApiOperation(value = "查看区位区号列表", notes = "查看区位区号列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "编辑区位区号", operDesc = "编辑区位区号")
    @PostMapping("/list")
    public Result<PageResponse<MainDataAreaNumberListDTO>> list(@RequestBody @Valid MainDataAreaNumberListReq req){
        return Result.success(iMainDataAreaNumberService.list(req));
    }



}
